package com.egao.ap.service.impl;

import com.egao.ap.entity.Settings;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.JsonResult;
import com.egao.common.system.entity.User;
//import com.egao.ap.mapper.InformationMapper;
import com.egao.ap.entity.Information;
import com.egao.ap.service.InformationService;
import com.sun.org.apache.bcel.internal.generic.IFNONNULL;
import org.springframework.stereotype.Service;
import com.egao.ap.biz.InformationBiz;
import net.sf.json.JSONObject;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
//import javax.transaction.Transactional;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 帖子服务实现类
 * @author : Doman
 * @date : 2020-10-12 14:21:51
 * @version ：1.0
 */
@Service
public class InformationServiceImpl /*extends ServiceImpl<InformationMapper, Information> */implements InformationService {

	@Autowired
	private InformationBiz informationBiz;

    @Override
    public JsonResult list(PageResult2<T> page, Information information, User loginUser)  throws Exception{
        return informationBiz.list(page,information,loginUser);
    }

    @Override
    public JsonResult list(PageResult2<T> page, Information information)  throws Exception{
        return informationBiz.list(page,information);
    }

    @Override
    public JsonResult list(Information information, User loginUser) {
        return JsonResult.ok().setData(informationBiz.list(information,loginUser));
    }

    @Override
    public JsonResult list(Information information) {
        return JsonResult.ok().setData(informationBiz.list(information));
    }

    @Override
    public JsonResult appList(Information information) {
        return JsonResult.ok().setData(informationBiz.appList(information));
    }

    @Override
    public JsonResult infoStateNum(Information information) {
        return JsonResult.ok().put("nums", informationBiz.infoStateNum(information));
    }

    @Override
    public JsonResult getById(Information information) {
        return JsonResult.ok().setData(informationBiz.getById(information));
    }

    @Override
    public JsonResult getByOpenid(Information information) {
        return JsonResult.ok().setData(informationBiz.getByOpenid(information));
    }

    @Override
    public JsonResult getByType(Settings settings) {
        return JsonResult.ok().setData(informationBiz.getByType(settings));
    }

    @Transactional
    @Override
    public JsonResult save(Information information, User loginUser) {
        information.setUserAvatar(loginUser.getAvatar());
        information.setUserId(loginUser.getUserId()+"");
        information.setUserNickName(loginUser.getNickName());
        information.setOpenid(loginUser.getXcxopenid());
        if (informationBiz.save(information, loginUser)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }

    @Transactional
    @Override
    public JsonResult update(Information information, User loginUser) {
        if (informationBiz.update(information, loginUser)) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }

    @Transactional
    @Override
    public JsonResult updateUpTime(Information information, User loginUser) {
        if (informationBiz.updateUpTime(information, loginUser)) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }

    @Transactional
    @Override
    public JsonResult updateState(Information information, User loginUser) {
        if (informationBiz.updateState(information, loginUser)) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }

    @Transactional
    @Override
    public JsonResult remove(Information information, User loginUser) {
        if (informationBiz.remove(information, loginUser)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }

}
